package com.hs.chd.action.data;
 
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellStyle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.hs.auth.model.HsAccount;
import com.hs.chd.catagory.SubjectUtil;
import com.hs.chd.model.ChdFileinfo;
import com.hs.chd.model.ChdImpfileinfo;
import com.hs.chd.model.ChdPaperinfo;
import com.hs.chd.model.ChdStandword;
import com.hs.chd.service.IDataService;
import com.hs.core.action.BaseAction;
import com.hs.core.cache.GlobalParamCache;
import com.hs.core.db.DBMgr;
import com.hs.core.imp.ExcelImportUtil;
import com.hs.core.utils.PageParam;
import com.hs.core.utils.PageUtil;
import com.hs.core.utils.SystemUtil;
import com.hs.core.utils.TimeUtil;
import com.hs.core.utils.Tools;
@Controller   
public class DataController  extends BaseAction {
    /**
	 * 
	 */
	private static final long serialVersionUID = -354434172898440670L;
	private static final Logger logger = Logger.getLogger(DataController.class);
	private IDataService dataService;
	@Autowired  
	public void setDataService(IDataService dataService) {
		this.dataService = dataService;
	}
	/**
	  * 方剂分类数据维护
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/standard/pretag.do", method = RequestMethod.GET)   
   public ModelAndView pretag(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		 DBMgr dbo = this.getDbo(request);
         Map treedata = getTreeStr(dbo,"1");
         modelMap.addAllAttributes(treedata);
		 return new ModelAndView("app/standard/pretag",modelMap);
		 
	 } 
	 /**
	  * 证候分类数据维护
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/standard/symtag.do", method = RequestMethod.GET)   
	 public ModelAndView symtag(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		 DBMgr dbo = this.getDbo(request);
         Map treedata = getTreeStr(dbo,"2");
         modelMap.addAllAttributes(treedata);
		 return new ModelAndView("app/standard/symtag",modelMap);
		 
	 } 
	 /**
	  * 中药分类数据维护
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/standard/herbtag.do", method = RequestMethod.GET)   
	 public ModelAndView herbtag(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		 DBMgr dbo = this.getDbo(request);
         Map treedata = getTreeStr(dbo,"3");
         modelMap.addAllAttributes(treedata);
		 return new ModelAndView("app/standard/herbtag",modelMap);
		 
	 } 
	 /**
	  * 病名分类数据维护
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/standard/distag.do", method = RequestMethod.GET)   
	 public ModelAndView distag(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		 DBMgr dbo = this.getDbo(request);
         Map treedata = getTreeStr(dbo,"4");
         modelMap.addAllAttributes(treedata);
		 return new ModelAndView("app/standard/distag",modelMap);
		 
	 } 
	 
	 /**
	  * 主题分类数据维护
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/standard/tagsframe.do", method = RequestMethod.GET)   
   public ModelAndView tagsframe(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		 
		 return new ModelAndView("app/standard/tagsframe",modelMap);
		 
	 } 
	 /**
	  * 标准数据管理框架页
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/standard/standdataframe.do", method = RequestMethod.GET)   
    public ModelAndView standdataframe(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
        
		 return new ModelAndView("app/standard/standlistframe",modelMap);
		 
	 } 
	 /**
	  * 标准数据列表
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/standard/standardlist.do")   
     public ModelAndView standardlist(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		 PageParam pageParam = new  PageParam(request,"standard/standardlist.do");
		 PageUtil pageUtil = null;
		 String orderName = request.getParameter("orderName");
		 String orderNum = request.getParameter("orderNum");
		 String datatype = "1";
		 StringBuffer orderByStr = new StringBuffer(" order by ");
		 if(StringUtils.isNotBlank(orderName)){
		    	if("1".equals(orderNum)){
		    		orderByStr.append(orderName).append(" asc");
		    	}
		    	if("2".equals(orderNum)){
		    		orderByStr.append(orderName).append(" desc");
		    	}
		    }else{
		    	orderByStr.append("a.rightname").append(" asc");
		    	orderName = "a.rightname";
		    	orderNum = "2";
		    }
		 request.setAttribute("orderName", orderName); 
		 request.setAttribute("orderNum", orderNum); 
		 pageParam.getConditionMap().put("orderName", orderName);
		 pageParam.getConditionMap().put("orderNum", orderNum);
		 StringBuffer searchBuffer = new StringBuffer(" select a from ChdStandword a where 1=1   ");
			String rightname = request.getParameter("rightname");  
 			//String periodicalname = request.getParameter("periodicalname"); 
			request.setAttribute("rightname", rightname==null?rightname:rightname.trim());
 			//request.setAttribute("periodicalname", periodicalname);
			if(StringUtils.isNotBlank(rightname)){
				String temp = rightname.trim();
				searchBuffer.append(" and (a.rightname like '%").append(temp).append("%' ");
				searchBuffer.append(" or a.othername like '%").append(temp).append("%') ");
				pageParam.getConditionMap().put("rightname", temp); 
			}  
//			if(StringUtils.isNotBlank(author)){
//				pageParam.getConditionMap().put("author", author.trim());
//				searchBuffer.append(" and (a.author like '%"+author.trim()+"%') "); 
//			}
//			 
			searchBuffer.append(orderByStr);
			//Map data = new HashMap();
			pageParam.setSearchSql(searchBuffer.toString());
			pageUtil = dataService.getPageList(pageParam);
			modelMap.put("dataList", pageUtil);     
		  return new ModelAndView("app/standard/standardlist",modelMap);
		 
	 }
	 /**
	  * 标准数据导入页面
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/standard/standimport.do", method = RequestMethod.GET)   
     public ModelAndView standimport(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		   	
		  return new ModelAndView("app/standard/standimportview",modelMap);
		 
	 }
	 /**
	  * 数据导入页面
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/data/dataimport.do")   
     public ModelAndView dataimport(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
			PageParam pageParam = new PageParam(request,"data/dataimport.do");
			String mSubject = request.getParameter("filename"); // 题名 
			StringBuffer searchBuffer = new StringBuffer(
					" select a from ChdImpfileinfo a where isdel=1 ");
			PageUtil pageUtil = null;
			
			if (StringUtils.isNotBlank(mSubject)) {
				searchBuffer.append(" and a.filename like '%").append(mSubject).append("%'"); 
				pageParam.getConditionMap().put("filename", mSubject);
				request.setAttribute("filename", mSubject);
			} 
			searchBuffer.append(" order by a.uploaddate");
			
			Map data = new HashMap();
			pageParam.setSearchSql(searchBuffer.toString());
			pageUtil = dataService.getPageList(pageParam);
			data.put("dataList", pageUtil); 
		  return new ModelAndView("app/data/importlist",data);
		 
	 }
	 
	 /**
	  * 标准数据导入
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	 * @throws Exception 
	  */
	 @RequestMapping(value="/data/pdfupload.do")   
     public void pdfupload(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws Exception {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;   
		 MultipartFile multipartFile = multipartRequest.getFile("pdffile");  
		 //String paperid = multipartRequest.getParameter("paperid");
		 String paperid = request.getParameter("paperid");
		 logger.debug("paperid:" + paperid);
		 logger.debug("String paperid = multipartRequest" +   multipartRequest.getParameter("paperid"));
		 String fileName = multipartFile.getOriginalFilename(); 
		// String webRoot = SystemUtil.getWebappRoot().toString();
		// webRoot = webRoot.replace("\\", "/") + "/temp"; 
		 String sep = System.getProperty("file.separator");
		 sep = "/"; 
//		 File rootDir = new File(webRoot); 
//		 if (!rootDir.exists()) {
//			rootDir.mkdirs(); 
//		 }
		 String sql = "update CHD_PAPERINFO set ISIMG=1 where id=?";
		 //查询该文献是否已经上传原文
		 this.getDbo(request).update(sql, new Object[]{paperid});
		 logger.debug("1");
		 HsAccount acc = this.getCurrentuser(request);
 		 String username = acc==null?"":acc.getUserinfo()==null?"":acc.getUserinfo().getUsername();
 		 String[] bookinfo = this.writePdfFile(multipartFile.getBytes(), fileName);
		 ChdFileinfo pdffile = new ChdFileinfo();
		 pdffile.setPapercontent(new String(multipartFile.getBytes()));
		 pdffile.setPaperid(new Long(paperid));
		 pdffile.setProdate(TimeUtil.getCurrentDate());
		 logger.debug("2");
		 pdffile.setProuser(username);
		 pdffile.setProversion(1l);
		 pdffile.setPapertitle(fileName);
		 pdffile.setSavepath(bookinfo[0]+bookinfo[1]);
		 this.dataService.saveObject(pdffile);
		 logger.debug("3");
//		 File file = new File(webRoot + sep + fileName);
//		 BufferedOutputStream bf = new BufferedOutputStream(new FileOutputStream(file));
//		 bf.write(multipartFile.getBytes());
//		 bf.close();
		 logger.debug("文件"+fileName+"上传成功!");
		 
		 response.getWriter().write("文件"+fileName+"上传成功!");
	 }
	 private String[] writePdfFile(byte[] fileContent,String fileName) throws Exception{
			String[] temp = new String[3];
			StringBuffer buffer = new StringBuffer();
			String sep = System.getProperty("file.separator");
			sep = "/"; 
			//存储路径
			String webRoot = GlobalParamCache.getInst().getParamByKey("filepath");// SystemUtil.getWebappRoot().getPath() + sep +  "upload";//SWFConvertUtil.getParamMap("filepath");// 
//			if(null != filesavepath)
//				webRoot = filesavepath;
			String middlePath = Tools.buildFileSubdirectory();
			String fileSaveUUID = com.hs.core.utils.UUIDGenerator.getUUID();
			String fullPath = webRoot + sep + middlePath;
			buffer.append(middlePath).append(sep);
			 
			logger.debug("fullPath:" + fullPath);
			File rootDir = new File(webRoot); 
			File directory = null;
			if (!rootDir.exists()) {
				rootDir.mkdirs(); 
			} 
			directory = new File(rootDir, middlePath);
			if(!directory.exists() && !directory.mkdirs()){
				logger.error("创建文件存储路径失败【" + directory.getAbsolutePath() + "】");
			}  
			 
			StringBuffer fileLocation = new StringBuffer(webRoot);
			StringBuffer fileFullPath = new StringBuffer();
			fileLocation.append(middlePath); 
			fileLocation.append(sep); 
			
			fileFullPath.append(middlePath); 
			fileFullPath.append(sep); 
			String fileSaveName = "";
			int pos = fileName.lastIndexOf('.');
			if (pos == -1) {
				fileSaveName = fileSaveUUID;
			} else {
				fileSaveName = fileSaveUUID + fileName.substring(pos);
			}
			//buffer.append(fileSaveName);
			temp[2] = fileLocation.toString();
			fileLocation.append(fileSaveName);
			fileFullPath.append(fileSaveName);
			 
			logger.info("to store file: " + fileLocation);
			File file = new File(fileLocation.toString());
			if(!file.exists()){
				file.createNewFile();
			}
			logger.info("file created!");
			BufferedOutputStream bf = new BufferedOutputStream(
					new FileOutputStream(file));
			bf.write(fileContent);
			bf.close();
			temp[0] = buffer.toString();
			temp[1] = fileSaveName;
			return temp;
		}
//	 @RequestMapping("/data/downloadFile.do")   
//		public   ModelAndView  downloadFile(HttpServletRequest request,
//				HttpServletResponse response, ModelAndView mv) throws Exception {
//				Map modelMap = new HashMap();
//				String pid = request.getParameter("pid");
//				Long fileid = this.getDbo(request).queryCountForLong("select max(id) from CHD_FILEINFO where paperid=?", new Object[]{pid});
//			    response.setCharacterEncoding("UTF-8");
//			    logger.debug("pid:"+pid);
//			    ChdFileinfo pobj = (ChdFileinfo)dataService.findByID(ChdFileinfo.class,fileid);
//			    InputStream inputStream = IOUtils.toInputStream(pobj.getPapercontent());
//			    
//				byte[] data = pobj.getPapercontent().getBytes();  
//				String filePath = SystemUtil.getWebappRoot().getPath() + "/upload";
//				FileOutputStream fileOutputStream = new FileOutputStream(filePath+"/"+pobj.getPapertitle());
//
//				//IOUtils.write(pobj.getPapercontent(),fileOutputStream);
//				String fileName = pobj.getPapertitle();
//				String ext = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length());
//	 			logger.debug("ext:" + ext);
//
////	 			  
//		        try{
//		        	int                 length   = 0;
//			        ServletOutputStream op       = response.getOutputStream();
//			        ServletContext      context  = request.getSession().getServletContext();
//			        String              mimetype = context.getMimeType( fileName );
////			        byte[]   byteContents   =   new   byte[fileLength];   
////			        FileInputStream fis   =   new   FileInputStream(file);   
////			        int   retcd   =   fis.read(byteContents);   
////			        fis.close();    
//			        logger.debug("mimetype:" + mimetype);
//			        response.setContentType(mimetype == null?"application/pdf":mimetype );
//			        response.setContentLength( data.length ); 
//			        response.setHeader( "Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("gb2312"),"ISO-8859-1") + "\"" );
//
//
//			          byte[] b=new byte[1024];
//			          
//			          int len=0;
//			          
//			          while((len=inputStream.read(b))!=-1){
//			           op.write(b, 0, len);
//			          }
//			      
//			      op.close();
//			      inputStream.close();
//
//
////			        response.setHeader( "Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("gb2312"),"ISO-8859-1") + "\"" );
//// 			        op.write(data,0,data.length); 
////			        op.flush();
//////			        op.flush(); 
////
//////			        int BUFSIZE = 2048;
//////			        byte[] bbuf = new byte[BUFSIZE];
////////			        FileInputStream fis = new FileInputStream(f);
////////			        DataInputStream in = new DataInputStream(new FileInputStream(f));
////		//
//////			        while ((fis != null) && ((length = fis.read(bbuf)) != -1))
//////			        {
//////			           	 op.write(bbuf,0,length);
//////			        }
////
////			       // fis.close();
////			       // op.flush();
////			        op.close();
//		            }catch(Exception e){
//		            	e.printStackTrace();
//		            }
//	// 
//	            return null;
//		}
	 @RequestMapping("/data/downloadFile.do")   
		public   ModelAndView  downloadFile(HttpServletRequest request,
				HttpServletResponse response, ModelAndView mv) throws Exception {
				Map modelMap = new HashMap();
				String pid = request.getParameter("pid");
			    response.setCharacterEncoding("UTF-8");
			    DBMgr dbo = DBMgr.getDbUtilInst(request.getSession().getServletContext());
			    List datalist = dbo.queryList("select PAPERTITLE,SAVEPATH from CHD_FILEINFO where id=(select max(id) from CHD_FILEINFO where PAPERID=?)", new Object[]{pid});
			    //ChdFileinfo pobj = (ChdFileinfo)dataService.findByID(ChdFileinfo.class, new Long(pid));
				String filePath = GlobalParamCache.getInst().getParamByKey("filepath");
				if(datalist.size()>0){
					Map filedata = (Map)datalist.get(0);
					String fileName = (String)filedata.get("PAPERTITLE");
					String ext = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length());
		 			logger.debug("ext:" + ext);
	
		 			String fileDbURL = (String)filedata.get("SAVEPATH");
		 			logger.debug("fileDbURL:" + fileDbURL);
		 			filePath += fileDbURL;
					logger.debug("test文件是否存在:" + new File(filePath).exists());
	
		 			filePath = filePath.replace("\\", "/");
		 			logger.debug("fileurl:" + filePath); 
					File file = new File(filePath);
					logger.debug("文件是否存在:" + file.exists());
			       
			        int fileLength = (int)file.length();
			        try{
			        	int                 length   = 0;
				        ServletOutputStream op       = response.getOutputStream();
				        ServletContext      context  = request.getSession().getServletContext();
				        String              mimetype = context.getMimeType( fileName );
				        byte[]   byteContents   =   new   byte[fileLength];   
				        FileInputStream fis   =   new   FileInputStream(file);   
				        int   retcd   =   fis.read(byteContents);   
				        fis.close();    
				        logger.debug("mimetype:" + mimetype);
				        response.setContentType(mimetype == null?"application/pdf":mimetype );
				        response.setContentLength( retcd );
				        response.setHeader( "Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("gb2312"),"ISO-8859-1") + "\"" );
	
				        op.write(byteContents,0,retcd); 
				        op.close();
			            }catch(Exception e){
			            	e.printStackTrace();
			            }
	             }
	            return null;
		}
	 /**
	  * 标准数据导入
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	 * @throws Exception 
	  */
	 @RequestMapping(value="/data/executestandardimport.do")   
     public void executestandardimport(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws Exception {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;   
		 MultipartFile multipartFile = multipartRequest.getFile("importfile");   
		 String fileName = multipartFile.getOriginalFilename(); 
		 String webRoot = SystemUtil.getWebappRoot().toString();
		 webRoot = webRoot.replace("\\", "/") + "/temp"; 
		 String sep = System.getProperty("file.separator");
		 sep = "/"; 
		 File rootDir = new File(webRoot); 
		 if (!rootDir.exists()) {
			rootDir.mkdirs(); 
		 }
		 File file = new File(webRoot + sep + fileName);
		 BufferedOutputStream bf = new BufferedOutputStream(new FileOutputStream(file));
		 bf.write(multipartFile.getBytes());
		 bf.close();
		 logger.debug("文件"+fileName+"上传成功!");
		 
		 HsAccount acc = this.getCurrentuser(request);
 		 String username = acc==null?"":acc.getUserinfo()==null?"":acc.getUserinfo().getUsername();
		 Map datamap  = this.checkAndImpData(file,username);
		 String info = (String)datamap.get("info");
		 List datalist = (List)datamap.get("datalist");
		 logger.debug("info:" + info);
		 logger.debug("datalist:" + datalist);
		 if(StringUtils.isNotEmpty(info)){
			 response.getWriter().write("错误信息:\n"+info);
		 }else{
			 this.dataService.saveOrUpdateAll(datalist);
			 response.getWriter().write("共导入标准数据【"+datalist.size()+"】条.");
		 }
		  
	    // return new ModelAndView("app/data/magaimportview",modelMap);
 		 
	 }
	 private Map checkAndImpData(File datafile,String impuser){
		 Map datamap = new HashMap();
		 StringBuffer buffer = new StringBuffer(""); 
		 List datalist = new ArrayList();
		 ExcelImportUtil inst = ExcelImportUtil.getInstance(datafile);
		 HSSFWorkbook workbook = null;
		 try {
				workbook = inst.readFile();
				int total = workbook.getNumberOfSheets(); //获取sheet个数      
		        int start = 0;
		        int end = 0 ;   
		        //获取sheet个数
		        Map doublemap = new HashMap();
				for(int i = 0 ; i < total ; i ++){  
		            HSSFSheet sheet = workbook.getSheetAt(i);// 按索引获取sheet引用   
		            start = sheet.getFirstRowNum();  //sheet起始行索引      
		            end = sheet.getLastRowNum();//sheet起结束行索引      
		            int counter = 1;      
		            HSSFRow row = null ; 
		            HSSFCell tcmname = null ; 
		        	HSSFCell tcmothername = null ;  
		        	
		            while(counter <= end){      
		            	ChdStandword std = null;
		                 row =  sheet.getRow(counter);//获取第N行表格数据     
		                 if(row != null){
		                	 counter ++ ;
		                	 tcmname = row.getCell(1);//获取指定列单元格            
		                	 tcmothername = row.getCell(2);    
		  		        	 String tcmstr = getCell(tcmname);
			                 String tcmothernamestr = getCell(tcmothername);
//			                 if(StringUtils.isNotEmpty(tcmstr)){
//			                	 String obj = (String)doublemap.get(tcmstr);
//			                	 if(null == obj){
//				                	 doublemap.put(tcmstr, tcmstr); 
//			                	 }else{
//			                		 buffer.append("第【"+counter +"】行正名存在重复数据.\n");
//			                	 }
//			                 } 
			                 if(StringUtils.isNotEmpty(tcmothernamestr)){
			                	 String obj = (String)doublemap.get(tcmothernamestr);
			                	 if(null == obj){
				                	 doublemap.put(tcmothernamestr, tcmothernamestr); 
			                	 }else{
			                		 buffer.append("第【"+counter +"】行异名存在重复数据.\n");
			                	 }
			                 } 
			                 
			                 if(StringUtils.isEmpty(tcmstr)){
			                	 buffer.append("第【"+counter +"】行数据错误，病名不能为空.\n");
			                	 continue;
			                 }
		  		        	 StringBuffer countsql = new StringBuffer();
			                 countsql.append("select id from CHD_STANDWORD ");
			                 countsql.append(" where RIGHTNAME='");
			                 countsql.append(tcmstr==null?null:tcmstr.trim().replaceAll("'", "''")); 
			                 countsql.append("'");
			                 if(StringUtils.isNotEmpty(tcmothernamestr)){
			                	 countsql.append(" and OTHERNAME='" + tcmothernamestr.trim() + "'");
			                 } 
			                 
							 List accList = DBMgr.getDbUtilInst().queryList(countsql.toString(),null);  
							 int acclen = accList.size();
							 if(acclen >0){ 
								 buffer.append("第【"+counter +"】行数据重复.\n");
								 continue;
							 }else{
								 std = new ChdStandword();  
				                 std.setImpuser(impuser);
				                 std.setRightname(tcmstr);
				                 std.setOthername(tcmothernamestr);
				                 std.setImpdate(TimeUtil.getCurrentDate());
				                 std.setIsdelete(new Long(0)); 
				                 datalist.add(std);
							 }
				                 
		                 }
		                  
		            } 
				}
			} catch (FileNotFoundException e) { 
				logger.debug("文件不存在:" + e.getMessage());
				buffer.append("数据文件读取异常，请重试.\n"+e.getMessage());
			} catch (IOException e) { 
				logger.debug("读取文件异常:" + e.getMessage());
				buffer.append("数据文件读取异常，请重试.\n"+e.getMessage());
			} catch (Exception e) {
				// TODO Auto-generated catch block
				buffer.append("数据文件读取异常，请重试.\n"+e.getMessage());
			}  
		 datamap.put("info", buffer.toString());
		 datamap.put("datalist", datalist);
 		 return datamap;
	 }
	 /**
	  * 数据导出
	  * @param request
	  * @param response
	  * @return
	 * @throws Exception 
	  */
	@RequestMapping("/standard/standardexport.do")   
	public ModelAndView standardexport(HttpServletRequest request,
			HttpServletResponse response) throws Exception { 
		try  {
			String path = this.exportStdData("");
			System.out.println("message::" + path );
			//  path是指欲下载的文件的路径。 
			response.setCharacterEncoding("UTF-8");
			File file  =   new  File(path);
			String filename  =  file.getName();
			int fileLength = (int)file.length();
			int                 length   = 0;
	        ServletOutputStream op       = response.getOutputStream();
	        ServletContext      context  = request.getSession().getServletContext();
	        String              mimetype = context.getMimeType( filename );
	        byte[]   byteContents   =   new   byte[fileLength];   
	        FileInputStream fis   =   new   FileInputStream(file);   
	        int   retcd   =   fis.read(byteContents);   
	        fis.close();    
	        logger.debug("mimetype:" + mimetype);
	        response.setContentType(mimetype == null?"application/vnd.ms-excel":mimetype );
	        response.setContentLength( retcd );
	        response.setHeader( "Content-Disposition", "attachment; filename=\"" + new String(filename.getBytes("gb2312"),"ISO-8859-1") + "\"" );
	        op.write(byteContents,0,retcd); 
	        op.close();
     }  catch  (IOException ex) {
         ex.printStackTrace();
     }
		return null;  
	} 
	 /**
	  * 数据管理主页
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/data/dataListFrame.do", method = RequestMethod.GET)   
     public ModelAndView dataListFrame(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		   	
		  return new ModelAndView("app/data/datalistframe",modelMap);
		 
	 }
	 /**
	  * 期刊文献数据主页
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/data/magalistframe.do", method = RequestMethod.GET)   
     public ModelAndView magalistframe(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		   	
		  return new ModelAndView("app/data/magalistframe",modelMap);
		 
	 }
	 /**
	  * 期刊文献数据列表
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/data/magalist.do")   
     public ModelAndView magalist(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		 PageParam pageParam = new  PageParam(request,"data/magalist.do");
		 PageUtil pageUtil = null;
		 String orderName = request.getParameter("orderName");
		 String orderNum = request.getParameter("orderNum");
		 String startdate = request.getParameter("startdate");
			String enddate = request.getParameter("enddate");
		 String datatype = "1";
		 StringBuffer orderByStr = new StringBuffer(" order by ");
		 if(StringUtils.isNotBlank(orderName)){
		    	if("1".equals(orderNum)){
		    		orderByStr.append(orderName).append(" asc");
		    	}
		    	if("2".equals(orderNum)){
		    		orderByStr.append(orderName).append(" desc");
		    	}
		    }else{
		    	orderByStr.append("a.title").append(" asc");
		    	orderName = "a.title";
		    	orderNum = "2";
		    }
		 request.setAttribute("orderName", orderName); 
		 request.setAttribute("orderNum", orderNum); 
		 request.setAttribute("startdate", startdate); 
		 request.setAttribute("enddate", enddate); 
		 
		 StringBuffer searchBuffer = new StringBuffer(" select a from ChdPaperinfo a where a.datatype<3   ");
			String title = request.getParameter("title");  
			String author = request.getParameter("author");  
			//String periodicalname = request.getParameter("periodicalname"); 
			request.setAttribute("title", title==null?title:title.trim());
			request.setAttribute("author", author==null?author:author.trim());
			//request.setAttribute("periodicalname", periodicalname);
			if(StringUtils.isNotBlank(title)){
				String temp = title.trim();
				searchBuffer.append(" and (a.title like '%").append(temp).append("%' ");
				searchBuffer.append(" or a.titlen like '%").append(temp).append("%') ");
				pageParam.getConditionMap().put("title", temp); 
			}  
			if(StringUtils.isNotBlank(author)){
				pageParam.getConditionMap().put("author", author.trim());
				searchBuffer.append(" and (a.author like '%"+author.trim()+"%') "); 
			}
			if(StringUtils.isNotBlank(startdate)){
				startdate = startdate.replaceAll("-", "");
				searchBuffer.append(" and to_date(a.impdate,'yyyy-MM-dd')>=to_date('").append(startdate).append("','yyyy-MM-dd') ");
				pageParam.getConditionMap().put("startdate", startdate);
			}
			if(StringUtils.isNotBlank(enddate)){
				enddate = enddate.replaceAll("-", "");
				searchBuffer.append(" and to_date(a.impdate,'yyyy-MM-dd')<=to_date('").append(enddate).append("','yyyy-MM-dd')");
				 pageParam.getConditionMap().put("enddate", enddate);

			}
//			 
			searchBuffer.append(orderByStr);
			logger.debug("orderByStr:" + searchBuffer);
			
			//Map data = new HashMap();
			pageParam.setSearchSql(searchBuffer.toString());
			pageUtil = dataService.getPageList(pageParam);
			modelMap.put("dataList", pageUtil);     
		  return new ModelAndView("app/data/magaList",modelMap);
		 
	 }
	 /**
	  * 期刊文献导入
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	 * @throws Exception 
	  */
	 @RequestMapping(value="/data/executemagaimport.do")   
     public void executemagaimport(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws Exception {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;   
		 MultipartFile multipartFile = multipartRequest.getFile("importfile");  
 		 HsAccount curUser = this.getCurrentuser(request); 
 		 String datatype =  "1"; 
		 String fileName = multipartFile.getOriginalFilename(); 
		 String webRoot = SystemUtil.getWebappRoot().toString();
		 webRoot = webRoot.replace("\\", "/") + "/temp"; 
		 String sep = System.getProperty("file.separator");
		 sep = "/"; 
		 File rootDir = new File(webRoot); 
		 if (!rootDir.exists()) {
			rootDir.mkdirs(); 
		 }
		 String filepath = webRoot + sep + fileName;
		 File file = new File(filepath);
		 BufferedOutputStream bf = new BufferedOutputStream(new FileOutputStream(file));
		 bf.write(multipartFile.getBytes());
		 bf.close();
		 logger.debug("文件"+fileName+"上传成功!"); 
		   //读取文件总行数
		   HSSFWorkbook workbook = null;
		   ChdImpfileinfo impFileInfo = new ChdImpfileinfo();
			try {
				FileInputStream rs = new FileInputStream(file);
				workbook = new HSSFWorkbook(rs); 
//				int total = workbook.getNumberOfSheets(); // 获取sheet个数
				int end = 0;
	 			//for (int i = 0; i < total; i++) {
				HSSFSheet sheet = workbook.getSheetAt(0);// 按索引获取sheet引用 
				end = sheet.getLastRowNum();// sheet起结束行索引
				//} 
				impFileInfo.setFilepath(filepath);
				impFileInfo.setFilename(fileName);
				impFileInfo.setUploaddate(TimeUtil.getCurrentDateTime());
				impFileInfo.setUploaduser(curUser==null?"":curUser.getUserinfo().getUsername());
				impFileInfo.setImpnum(0l);
				impFileInfo.setImpnum(new Long(end));
				impFileInfo.setImpfailpos(0l);
				impFileInfo.setIsdel(1l);
				impFileInfo.setDatatype(new Long(datatype));
				impFileInfo.setImpstatus(1l);
				impFileInfo.setImpcurrnum(0l);
				dataService.save(impFileInfo); 
				response.getWriter().flush();
				response.getWriter().close();
				response.getWriter().write("现代文献数据文件上传成功,请在数据导入模块执行数据导入操作!");

			}catch(Exception e){
				dataService.deleteObject(impFileInfo);
			}
		// HsAccount acc = this.getCurrentuser(request);
		// long userid = acc==null?0l:acc.getId();
		// int  nums[] =  this.importMaga(file,userid,isdouble);
		// response.getWriter().write("导入数据【"+nums[0]+"】条,更新数据【"+nums[1]+"】");
	    // return new ModelAndView("app/data/magaimportview",modelMap);
 		 
	 }
	 private int[] importMaga(File datafile,Long impuser,String isdouble) throws Exception{
		 int newcountnum = 0;
		 int updatecountnum = 0;
		 ExcelImportUtil inst = ExcelImportUtil.getInstance(datafile);
		 HSSFWorkbook workbook = null;
		 try {
				workbook = inst.readFile();
				int total = workbook.getNumberOfSheets(); //获取sheet个数      
		        int start = 0;
		        int end = 0 ;   
		        SubjectUtil util = SubjectUtil.getInst();
		        //获取sheet个数
				for(int i = 0 ; i < total ; i ++){  
		            HSSFSheet sheet = workbook.getSheetAt(i);// 按索引获取sheet引用   
		            start = sheet.getFirstRowNum();  //sheet起始行索引      
		            end = sheet.getLastRowNum();//sheet起结束行索引      
		            int counter = 1;      
		            HSSFRow row = null ; 
		            HSSFCell classno = null ; 
		        	HSSFCell title = null ;  
		        	HSSFCell author = null ;    
		        	HSSFCell authorunit = null ;
		        	HSSFCell areastr = null ; 
		        	HSSFCell cwnum = null ;
		        	
		        	HSSFCell periodicalname = null ;  
		        	HSSFCell yearstr = null ;
		        	
		        	HSSFCell volume = null ;   
		        	HSSFCell period = null ; 
		        	HSSFCell pageno = null ; 
		        	HSSFCell issnstr = null ; 
		        	HSSFCell contrycode = null ; 
		        	HSSFCell codestr = null ;
		        	HSSFCell publisharea = null ;
		        	
		        	HSSFCell keyword = null ;  
		        	HSSFCell subjectword = null ; 
		        	HSSFCell impressword = null ; 
		        	HSSFCell updatedate = null ; 
		        	HSSFCell titlen = null ;   
		        	HSSFCell abstract_ = null ;  
		        	HSSFCell authorabstract = null ; 
		        	HSSFCell documenttype = null ;  
		        	HSSFCell fundstr = null ; 
		        	HSSFCell language = null ;   
		        	HSSFCell usersubject = null ; 
		        	HSSFCell castr = null ;   

//		        	 
		            while(counter <= end){      
		            	 ChdPaperinfo maga = null;
		                 row =  sheet.getRow(counter);//获取第N行表格数据     
		                 if(row != null){
		                	  counter ++ ;
		                	  classno = row.getCell(0);//获取指定列单元格            
		                	  title = row.getCell(1);   
		                	  author = row.getCell(2);
		                	  authorunit = row.getCell(3);
		                	  areastr = row.getCell(4);
		                	  cwnum = row.getCell(5);
		                	  periodicalname = row.getCell(6);
		                	  yearstr = row.getCell(7);
		                	  volume = row.getCell(8);
		                	  period = row.getCell(9);
		                	  pageno = row.getCell(10);
		                	  issnstr = row.getCell(11); 
		  		        	  contrycode = row.getCell(12);
		  		        	  codestr = row.getCell(13);
		  		        	  publisharea = row.getCell(14);
		  		        	
		  		        	  keyword = row.getCell(15); 
		  		        	  subjectword = row.getCell(16); 
		  		        	  impressword = row.getCell(17);
		  		        	  updatedate = row.getCell(18); 
		  		        	  titlen = row.getCell(19);  
		  		        	  abstract_ = row.getCell(20);  
		  		        	  authorabstract = row.getCell(21);
		  		        	  documenttype = row.getCell(22); 
		  		        	  fundstr = row.getCell(23);
		  		        	  language = row.getCell(24);  
		  		        	  usersubject = row.getCell(25); 
		  		        	  castr = row.getCell(26);   
		  		        	  
		  		        	  //是否查重
		  		        	 if("1".equals(isdouble)){
			  		        	 String titlestr = getCell(title);
				                 String periodicalnamestr = getCell(periodicalname);
			  		        	 String yearstr1 = getCell(yearstr);
				                 String volumestr = getCell(volume);
				                 String periodstr = getCell(period);
			  		        	 StringBuffer countsql = new StringBuffer();
				                 countsql.append("select id from CHD_PAPERINFO ");
				                 countsql.append(" where title='");
				                 countsql.append(titlestr==null?null:titlestr.trim().replaceAll("'", "''")); 
				                 countsql.append("' and periodicalname='");
				                 countsql.append(periodicalnamestr==null?null:periodicalnamestr.trim().replaceAll("'", "''") + "'");
				                 
				                 if(StringUtils.isNotEmpty(yearstr1)){
				                	 countsql.append(" and yearstr='" + yearstr1.trim() + "'");
				                 }
	//			                 if(StringUtils.isNotEmpty(volumestr)){
	//			                	 countsql.append(" and volume='" + volumestr.trim() + "'");
	//			                 }
				                 if(StringUtils.isNotEmpty(periodstr)){
				                	 countsql.append(" and period='" + periodstr.trim() + "'");
				                 }
				                
								 List accList = DBMgr.getDbUtilInst().queryList(countsql.toString(),null);  
								 int acclen = accList.size();
								 if(acclen >0){
									 Map data = (Map)accList.get(0);
								     String id = data.get("id") + "";
								     maga = (ChdPaperinfo)dataService.findByID(ChdPaperinfo.class, new Long(id));
								     updatecountnum ++;
								 }else{
									 maga = new ChdPaperinfo();
									 newcountnum++;
								 }
		  		        	 }else if("2".equals(isdouble)){
		  		        		 maga = new ChdPaperinfo();
								 newcountnum++;
		  		        	 }
							 
				                 if(null != classno){
				                	 maga.setClassno(getCell(classno).trim()); 
				                 }else{
				                	 maga.setClassno("");
				                 }
				                 if(null != title){
				                	 maga.setTitle(getCell(title).trim()); 
				                 }else{
				                	 maga.setTitle("");
				                 }
				                 if(null != author){
				                	 maga.setAuthor(getCell(author).trim()); 
				                 }else{
				                	 maga.setAuthor("");
				                 }
				                 if(null != authorunit){
				                	 maga.setAuthorunit(getCell(authorunit).trim()); 
				                 }else{
				                	 maga.setAuthorunit("");
				                 }
				                 if(null != areastr){
				                	 maga.setAreastr(getCell(areastr).trim()); 
				                 }else{
				                	 maga.setAreastr("");
				                 }
				                 if(null != cwnum){
				                	 maga.setCwnum(getCell(cwnum).trim()); 
				                 }else{
				                	 maga.setCwnum("");
				                 }
				                 if(null != periodicalname){
				                	 maga.setPeriodicalname(getCell(periodicalname).trim()); 
				                 }else{
				                	 maga.setPeriodicalname("");
				                 }
				                 if(null != yearstr){
				                	 maga.setYearstr(getCell(yearstr).trim()); 
				                 }else{
				                	 maga.setYearstr("");
				                 }
				                 if(null != volume){
				                	 maga.setVolume(getCell(volume).trim()); 
				                 }else{
				                	 maga.setVolume("");
				                 }
				                 if(null != period){
				                	 maga.setPeriod(getCell(period).trim()); 
				                 }else{
				                	 maga.setPeriod("");
				                 }
				                 if(null != pageno){
				                	 maga.setPageno(getCell(pageno).trim()); 
				                 }else{
				                	 maga.setPageno("");
				                 }
				                 if(null != issnstr){
				                	 maga.setIssnstr(getCell(issnstr).trim()); 
				                 }else{
				                	 maga.setIssnstr("");
				                 }
				                 if(null != contrycode){
				                	 maga.setContrycode(getCell(contrycode).trim()); 
				                 }else{
				                	 maga.setContrycode("");
				                 }
				                 if(null != codestr){
				                	 maga.setCodestr(getCell(codestr).trim()); 
				                 }else{
				                	 maga.setCodestr("");
				                 }
				                 if(null != publisharea){
				                	 maga.setPublisharea(getCell(publisharea).trim()); 
				                 }else{
				                	 maga.setPublisharea("");
				                 }
				                 if(null != keyword){
				                	 maga.setKeyword(getCell(keyword).trim()); 
				                 }else{
				                	 maga.setKeyword("");
				                 }
				                 if(null != subjectword){
				                	 maga.setSubjectword(getCell(subjectword).trim()); 
				                 }else{
				                	 maga.setSubjectword("");
				                 }
				                 if(null != impressword){
				                	 maga.setImpressword(getCell(impressword).trim()); 
				                 }else{
				                	 maga.setImpressword("");
				                 }
				                 if(null != updatedate){
				                	 maga.setUpdatedate(getCell(updatedate).trim()); 
				                 }else{
				                	 maga.setUpdatedate("");
				                 }
				                 if(null != titlen){
				                	 maga.setTitlen(getCell(titlen).trim()); 
				                 }else{
				                	 maga.setTitlen("");
				                 }
				                 if(null != abstract_){
				                	 String temp = getCell(abstract_).trim();
				                	 String temp2 = "";
 				                	 if(temp.length()>=4000)
				                		 temp2 = temp.substring(0,3990);
				                	 maga.setAbstract_(temp2); 
				                 }else{
				                	 maga.setAbstract_("");
				                 }
				                 if(null != authorabstract){
				                	 maga.setAuthorabstract(getCell(authorabstract).trim()); 
				                 }else{
				                	 maga.setAuthorabstract("");
				                 }
				                 if(null != documenttype){
				                	 maga.setDocumenttype(getCell(documenttype).trim()); 
				                 }else{
				                	 maga.setDocumenttype("");
				                 }
				                 if(null != fundstr){
				                	 maga.setFundstr(getCell(fundstr).trim()); 
				                 }else{
				                	 maga.setFundstr("");
				                 } 
				                 if(null != language){
				                	 maga.setLanguage(getCell(language).trim()); 
				                 }else{
				                	 maga.setLanguage("");
				                 }  
				                 if(null != usersubject){
				                	 maga.setUsersubject(getCell(usersubject).trim()); 
				                 }else{
				                	 maga.setUsersubject("");
				                 }  
				                 if(null != castr){
				                	 maga.setCastr(getCell(castr).trim()); 
				                 }else{
				                	 maga.setCastr("");
				                 }
				                 
//							     if(acclen == 0){
//							    	 maga.setDatatype(new Long(1));
//							    	 maga.setImpdate(TimeUtil.getCurrentstr());
//							    	 maga.setIsimg(new Long(0));
//							    	 dataService.saveObject(maga);
//  							     }else {
//							    	 Map data = (Map)accList.get(0);
//								     String id = data.get("id") + "";
////								     WdssResource obj = (WdssResource)wdssService.findByID(WdssResource.class, new Long(id));
//								     
//							    	 StringBuffer usql = new StringBuffer("update wdss_resource set BOOKNAME=?,AUTHOR=?,SUBJECTWORD=?,KEYWORD=?,ABSTRACT=?,PUBLISHUNIT=?,");
//							    	 usql.append("PUBLISHADDRESS=?,PUBLISHDATE=?,ISBNSTR=?,BANCI=?,YINCI=?,ZISHU=?");
//							    	 usql.append(" where id=?");
////							    	 Object[] obj = new Object[]{maga.getBookname(),maga.getAuthor(),maga.getSubjectword(),maga.getKeyword(),maga.getAbstract_(),maga.getPublishunit(),
////							    			 maga.getPublishaddress(),maga.getPublishdate(),maga.getIsbnstr(),maga.getBanci(),maga.getYinci(),maga.getZishu(),id};
////							    	 DBMgr.getDbUtilInst().update(usql.toString(), obj);
//							     }
							     if("eng".equals(maga.getLanguage())){
							    	 maga.setDatatype(new Long(2));
							     }else{
							    	 maga.setDatatype(new Long(1));
							     }
						    	 maga.setImpdate(TimeUtil.getCurrentDate());
						    	 maga.setIsimg(new Long(0));
						    	 maga.setImpuser(impuser);
						    	 dataService.saveObject(maga);
						    	 
						    	
		                 }
		                  
		            } 
				}
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				logger.debug("文件不存在:" + e.getMessage());
				throw e;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				logger.debug("读取文件异常:" + e.getMessage());
				throw e;
			}  
		 int[] returndata = {newcountnum,updatecountnum};
		 return returndata;
	 }
	 /**
	  * 期刊文献页面
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/data/magaimportview.do", method = RequestMethod.GET)   
     public ModelAndView magaimportview(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		   	
		  return new ModelAndView("app/data/magaimportview",modelMap);
		 
	 }
	 /**
	  * 古籍文献数据列表
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/data/booklistframe.do", method = RequestMethod.GET)   
     public ModelAndView booklistframe(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		   	
		  return new ModelAndView("app/data/booklistframe",modelMap);
		 
	 }
	 /**
	  * 古籍文献数据列表
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/data/bookList.do")   
     public ModelAndView bookList(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		 PageParam pageParam = new  PageParam(request,"data/bookList.do");
		 PageUtil pageUtil = null;
		 String orderName = request.getParameter("orderName");
		 String orderNum = request.getParameter("orderNum"); 
		 StringBuffer orderByStr = new StringBuffer(" order by ");
		 if(StringUtils.isNotBlank(orderName)){
		    	if("1".equals(orderNum)){
		    		orderByStr.append(orderName).append(" asc");
		    	}
		    	if("2".equals(orderNum)){
		    		orderByStr.append(orderName).append(" desc");
		    	}
		    }else{
		    	orderByStr.append("a.bookname").append(" asc");
		    	orderName = "a.bookname";
		    	orderNum = "2";
		    }
		 request.setAttribute("orderName", orderName); 
		 request.setAttribute("orderNum", orderNum); 
		 pageParam.getConditionMap().put("orderName", orderName);
		 pageParam.getConditionMap().put("orderNum", orderNum);
		 StringBuffer searchBuffer = new StringBuffer(" select a from ChdPaperinfo a where a.datatype=3   ");
			String bookname = request.getParameter("bookname");  
			String tcmname = request.getParameter("tcmname");  
			String booktext = request.getParameter("booktext"); 

			//String periodicalname = request.getParameter("periodicalname"); 
			request.setAttribute("bookname", bookname==null?"":bookname.trim());
			request.setAttribute("tcmname", tcmname==null?"":tcmname.trim());
			request.setAttribute("booktext", booktext==null?"":booktext.trim());
			//request.setAttribute("periodicalname", periodicalname);
			if(StringUtils.isNotBlank(bookname)){
				String temp = bookname.trim();
				searchBuffer.append(" and a.bookname like '%").append(temp).append("%' ");
				pageParam.getConditionMap().put("bookname", temp); 
				pageParam.getConditionMap().put("title", temp); 
			}  
			if(StringUtils.isNotBlank(tcmname)){
				pageParam.getConditionMap().put("tcmname", tcmname.trim());
				searchBuffer.append(" and (a.tcmname like '%"+tcmname.trim()+"%') "); 
			}
			if(StringUtils.isNotBlank(booktext)){
				pageParam.getConditionMap().put("booktext", booktext.trim());
				searchBuffer.append(" and (a.originaltext like '%"+booktext.trim()+"%') "); 
			}
//			 
			
			
			searchBuffer.append(orderByStr);
			logger.debug("sql:"+searchBuffer);
			//Map data = new HashMap();
			pageParam.setSearchSql(searchBuffer.toString());
			pageUtil = dataService.getPageList(pageParam);
			modelMap.put("dataList", pageUtil);     
		  return new ModelAndView("app/data/bookList",modelMap);
		 
	 }
	 /**
	  * 书籍文献导入
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	 * @throws Exception 
	  */
	 @RequestMapping(value="/data/executebookimport.do")   
     public void executebookimport(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws Exception {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;   
		 MultipartFile multipartFile = multipartRequest.getFile("importfile");   
		 String fileName = multipartFile.getOriginalFilename(); 
		 String webRoot = SystemUtil.getWebappRoot().toString();
		 webRoot = webRoot.replace("\\", "/") + "/temp"; 
		 String sep = System.getProperty("file.separator");
		 HsAccount curUser = this.getCurrentuser(request); 
 		 String datatype =  "2"; 
		 sep = "/"; 
		 File rootDir = new File(webRoot); 
		 if (!rootDir.exists()) {
			rootDir.mkdirs(); 
		 }
		 String filepath = webRoot + sep + fileName;
		 File file = new File(filepath);
		 BufferedOutputStream bf = new BufferedOutputStream(new FileOutputStream(file));
		 bf.write(multipartFile.getBytes());
		 bf.close();
		 logger.debug("文件"+fileName+"上传成功!");
		 //读取文件总行数
		   HSSFWorkbook workbook = null;
		   ChdImpfileinfo impFileInfo = new ChdImpfileinfo();
			try {
				FileInputStream rs = new FileInputStream(file);
				workbook = new HSSFWorkbook(rs); 
//				int total = workbook.getNumberOfSheets(); // 获取sheet个数
				int end = 0;
	 			//for (int i = 0; i < total; i++) {
				HSSFSheet sheet = workbook.getSheetAt(0);// 按索引获取sheet引用 
				end = sheet.getLastRowNum();// sheet起结束行索引
				//} 
				impFileInfo.setFilepath(filepath);
				impFileInfo.setFilename(fileName);
				impFileInfo.setUploaddate(TimeUtil.getCurrentDateTime());
				impFileInfo.setUploaduser(curUser==null?"":curUser.getUserinfo().getUsername());
				impFileInfo.setImpnum(0l);
				impFileInfo.setImpnum(new Long(end));
				impFileInfo.setImpfailpos(0l);
				impFileInfo.setIsdel(1l);
				impFileInfo.setDatatype(new Long(datatype));
				impFileInfo.setImpstatus(1l);
				impFileInfo.setImpcurrnum(0l);
				dataService.save(impFileInfo); 
				response.getWriter().flush();
				response.getWriter().close();
				response.getWriter().write("古籍数据文件上传成功,请在数据导入模块执行数据导入操作!");

			}catch(Exception e){
				dataService.deleteObject(impFileInfo);
			}
//		 HsAccount acc = this.getCurrentuser(request);
//		 long userid = acc==null?0l:acc.getId();
//		 int  nums[] = this.importBook(file,userid);
//	     response.getWriter().write("导入数据【"+nums[1]+"】条,更新数据【"+nums[0]+"】");
 		 
	 }
	 private int[] importBook(File datafile,Long impuser) throws Exception{
		 int countnum = 0;
		 ExcelImportUtil inst = ExcelImportUtil.getInstance(datafile);
		 HSSFWorkbook workbook = null;
	        int newobj = 0;

		 try {
				workbook = inst.readFile();
				int total = workbook.getNumberOfSheets(); //获取sheet个数      
		        int start = 0;
		        int end = 0 ;   
		        //获取sheet个数
				for(int i = 0 ; i < total ; i ++){  
		            HSSFSheet sheet = workbook.getSheetAt(i);// 按索引获取sheet引用   
		            start = sheet.getFirstRowNum();  //sheet起始行索引      
		            end = sheet.getLastRowNum();//sheet起结束行索引      
		            int counter = 1;      
		            HSSFRow row = null ; 
		             
		        	HSSFCell bookname = null ;    
		        	HSSFCell tcmname = null ;   
		        	HSSFCell originaltext = null ;   
		        	HSSFCell volumesection = null ;   
		        	HSSFCell bookversion = null ; 
		        	HSSFCell inputuser = null ; 
		        	HSSFCell inputdate = null ;  
		        	HSSFCell chaodai = null ; 
		            while(counter <= end){      
		            	 ChdPaperinfo maga = null; 
		                 row =  sheet.getRow(counter);//获取第N行表格数据     
		                 if(row != null){
		                	  counter ++ ; 
		                	  bookname = row.getCell(1);
		                	  tcmname = row.getCell(2);
		                	  originaltext = row.getCell(3);
		                	  volumesection = row.getCell(4);
		                	  bookversion = row.getCell(5);
		                	  inputuser = row.getCell(6);
		                	  inputdate = row.getCell(7); 
		                	  chaodai = row.getCell(8); 
		                	  StringBuffer countsql = new StringBuffer();
				                 countsql.append("select id from CHD_PAPERINFO ");
				                 countsql.append(" where originaltext='");
				                 countsql.append(getCell(originaltext)==null?"":getCell(originaltext).trim().replaceAll("'", "''"));  
				                 countsql.append("'");
				                 String tcmname1 = getCell(tcmname);
				                 String juance = getCell(volumesection); 
//				                 String version = getCell(bookversion);
//				                 
//				                 if(StringUtils.isNotEmpty(tcmname1)){
//				                	 countsql.append(" and TCMNAME='");  
//				                	 countsql.append(tcmname1.trim().replaceAll("'", "''"));  
//				                	 countsql.append("'");  
////				                	 logger.debug("tmcname:"+tcmname1.trim());
//				                 }
				                 if(StringUtils.isNotEmpty(juance)){
				                	 countsql.append(" and VOLUMESECTION='");  
				                	 countsql.append(juance.trim().replaceAll("'", "''"));  
				                	 countsql.append("'");  
				                	 
				                 }
//				                 if(StringUtils.isNotEmpty(version)){
//				                	 countsql.append(" and BOOKVERSION='");  
//				                	 countsql.append(version.trim().replaceAll("'", "''"));  
//				                	 countsql.append("'");  
////				                	 logger.debug("version:"+version.trim());
//				                 }
								 List accList = DBMgr.getDbUtilInst().queryList(countsql.toString(),null);  
								 int acclen = accList.size(); 
								 
							     if(acclen > 0){
							    	 Map data = (Map)accList.get(0);
								     String id = data.get("id") + "";
								     maga = (ChdPaperinfo)dataService.findByID(ChdPaperinfo.class, new Long(id));
							    	 countnum++; 
								 }else{
									 maga = new ChdPaperinfo();
									 newobj ++;
								 }
		                	   
				                 if(null != bookname){
				                	 maga.setBookname(getCell(bookname).trim()); 
				                 }else{
				                	 maga.setBookname("");
				                 }
				                 if(null != tcmname){
				                	 maga.setTcmname(getCell(tcmname).trim()); 
				                 }else{
				                	 maga.setTcmname("");
				                 }
				                 if(null != originaltext){
				                	 maga.setOriginaltext(getCell(originaltext).trim()); 
				                 }else{
				                	 maga.setOriginaltext("");
				                 }
				                 if(null != volumesection){
				                	 maga.setVolumesection(getCell(volumesection).trim()); 
				                 }else{
				                	 maga.setVolumesection("");
				                 }
				                 if(null != bookversion){
				                	 maga.setBookversion(getCell(bookversion).trim()); 
				                 }else{
				                	 maga.setBookversion("");
				                 }
				                 if(null != inputuser){
				                	 maga.setInputuser(getCell(inputuser).trim()); 
				                 }else{
				                	 maga.setInputuser("");
				                 }
				                 if(null != inputdate){
				                	 maga.setInputdate(getCell(inputdate).trim()); 
				                 }else{
				                	 maga.setInputdate("");
				                 }
				                 if(null != chaodai){
				                	 maga.setBookcd(getCell(chaodai).trim()); 
				                 }else{
				                	 maga.setBookcd("");
				                 }
				                  
				                 
//							     else {
//							    	 Map data = (Map)accList.get(0);
//								     String id = data.get("id") + "";
////								     WdssResource obj = (WdssResource)wdssService.findByID(WdssResource.class, new Long(id));
//								     
//							    	 StringBuffer usql = new StringBuffer("update wdss_resource set BOOKNAME=?,AUTHOR=?,SUBJECTWORD=?,KEYWORD=?,ABSTRACT=?,PUBLISHUNIT=?,");
//							    	 usql.append("PUBLISHADDRESS=?,PUBLISHDATE=?,ISBNSTR=?,BANCI=?,YINCI=?,ZISHU=?");
//							    	 usql.append(" where id=?");
////							    	 Object[] obj = new Object[]{maga.getBookname(),maga.getAuthor(),maga.getSubjectword(),maga.getKeyword(),maga.getAbstract_(),maga.getPublishunit(),
////							    			 maga.getPublishaddress(),maga.getPublishdate(),maga.getIsbnstr(),maga.getBanci(),maga.getYinci(),maga.getZishu(),id};
////							    	 DBMgr.getDbUtilInst().update(usql.toString(), obj);
//							     }
							     maga.setDatatype(new Long(3));
						    	 maga.setImpdate(TimeUtil.getCurrentDate());
						    	 maga.setIsimg(new Long(0));
						    	 maga.setImpuser(impuser);
						    	 dataService.saveObject(maga);
		                 }
		                  
		            } 
				}
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				logger.debug("文件不存在:" + e.getMessage());
				throw e;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				logger.debug("读取文件异常:" + e.getMessage());
				throw e;
			}  
			int returndata[] = {countnum,newobj};
 		 return returndata;
	 }
	 /**
	  * 古籍文献页面
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/data/bookimportview.do", method = RequestMethod.GET)   
     public ModelAndView bookimportview(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		   	
		  return new ModelAndView("app/data/bookimportview",modelMap);
		 
	 }
	 
	 
	 /**
	  * 数据管理列表
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/data/dataList.do")   
     public ModelAndView dataList(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
		 PageParam pageParam = new  PageParam(request,"data/dataList.do");
		 PageUtil pageUtil = null;
		 String orderName = request.getParameter("orderName");
		 String orderNum = request.getParameter("orderNum");
		 StringBuffer orderByStr = new StringBuffer(" order by ");
		 if(StringUtils.isNotBlank(orderName)){
		    	if("1".equals(orderNum)){
		    		orderByStr.append(orderName).append(" asc");
		    	}
		    	if("2".equals(orderNum)){
		    		orderByStr.append(orderName).append(" desc");
		    	}
		    }else{
		    	orderByStr.append("a.state").append(" desc");
		    	orderName = "a.state";
		    	orderNum = "2";
		    }
		 request.setAttribute("orderName", orderName); 
		 request.setAttribute("orderNum", orderNum); 
		 pageParam.getConditionMap().put("orderName", orderName);
		 pageParam.getConditionMap().put("orderNum", orderNum);
		 StringBuffer searchBuffer = new StringBuffer(" select a from DnmsMagazine a where 1=1  ");
			String state = request.getParameter("state");  
			String maganame = request.getParameter("maganame");  
			String periodicalname = request.getParameter("periodicalname"); 
			request.setAttribute("state", state);
			request.setAttribute("maganame", maganame);
			request.setAttribute("periodicalname", periodicalname);
			if(StringUtils.isNotBlank(maganame)){
				searchBuffer.append(" and (a.maganame like '%").append(maganame).append("%' ");
				searchBuffer.append(" or a.titleeng like '%").append(maganame).append("%') ");
				pageParam.getConditionMap().put("maganame", maganame);
				request.setAttribute("maganame", maganame);
			}  
			if(StringUtils.isNotBlank(periodicalname)){
				pageParam.getConditionMap().put("periodicalname", periodicalname);
				searchBuffer.append(" and (a.periodicalname like '%"+periodicalname+"%') "); 
			}
//			if(StringUtils.isNotBlank(state)){
//				pageParam.getConditionMap().put("state", state);
//				if("0".equals(state)){
//					searchBuffer.append(" and (a.dataproducer is null ) "); 
//				}else if("1".equals(state)){
//					searchBuffer.append(" and (a.dataproducer is not null ) "); 
//				}
//			}
			searchBuffer.append(orderByStr);
			Map data = new HashMap();
			pageParam.setSearchSql(searchBuffer.toString());
			pageUtil = dataService.getPageList(pageParam);
 			data.put("dataList", pageUtil);     
		 return new ModelAndView("app/data/dataList",data);
		 
	 }  
	 /**
	  * 数据导入主页
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/data/dataImport.do", method = RequestMethod.GET)   
     public ModelAndView dataImport(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
         
		 return new ModelAndView("app/data/dataimport",modelMap);
		 
	 } 
	 
	 /**
	  * 数据修改
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/data/saveData.do", method = RequestMethod.GET)   
     public ModelAndView saveData(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
         
		 return new ModelAndView("app/data/dataList",modelMap);
		 
	 } 
	 /**
	  * 数据删除
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/data/dataDelete.do", method = RequestMethod.GET)   
     public ModelAndView dataDelete(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
         
		 return new ModelAndView("app/data/dataList",modelMap);
		 
	 }  
	public String getCell(HSSFCell cell){
		if(cell==null)return "";
		switch(cell.getCellType()){
			case HSSFCell.CELL_TYPE_NUMERIC:
				return (long)cell.getNumericCellValue() + "";
			case HSSFCell.CELL_TYPE_STRING:
				return cell.getStringCellValue();
			case HSSFCell.CELL_TYPE_FORMULA:
				return cell.getCellFormula();
			case HSSFCell.CELL_TYPE_BLANK:
				return "";
			case	HSSFCell.CELL_TYPE_BOOLEAN:
				return cell.getBooleanCellValue() + "";
			case HSSFCell.CELL_TYPE_ERROR:
	    	    return cell.getErrorCellValue() + "";
	    	default:
	    		return "";
		}
	}
	 /**
	  * 数据导出
	  * @param request
	  * @param response
	  * @return
	 * @throws Exception 
	  */
	@RequestMapping("/data/dataExport.do")   
	public ModelAndView dataExport(HttpServletRequest request,
			HttpServletResponse response) throws Exception { 
		try  {
			String path = this.exportData("");
			System.out.println("message::" + request.getRequestURL() );
			
           //  path是指欲下载的文件的路径。 
          File file  =   new  File(path);
          String filename  =  file.getName();
         //  取得文件的后缀名。 
           InputStream fis  =   new  BufferedInputStream( new  FileInputStream(path));
           byte [] buffer  =   new   byte [fis.available()];
          fis.read(buffer);
          fis.close();
          response.reset();
          response.setCharacterEncoding("UTF-8");
          System.out.println("下载文件开始" +   new  String(filename.getBytes("gb2312"),"ISO-8859-1")); 
          response.setHeader( "Content-Disposition", "attachment; filename=\"" + new String(filename.getBytes("gb2312"),"ISO-8859-1") + "\"" );
          response.addHeader( " Content-Length " ,  ""   +  file.length());
          OutputStream toClient  =   new  BufferedOutputStream(response.getOutputStream());
          response.setContentType( "application/vnd.ms-excel" );
          toClient.write(buffer);
          toClient.flush();
          toClient.close();
      }  catch  (IOException ex) {
          ex.printStackTrace();
      }
		return null;  
	} 
	 /**
	  * 中英文期刊数据导出
	  * @param request
	  * @param response
	  * @return
	 * @throws Exception 
	  */
	@RequestMapping("/data/exportData.do")   
	public ModelAndView exportData(HttpServletRequest request,
			HttpServletResponse response) throws Exception { 
		try  {
			String ids = request.getParameter("ids");
			if(StringUtils.isEmpty(ids)){
				return null;
			}else{
				ids = ids.substring(0,ids.length()-1);
			}
			String path = this.exportData(ids);
			System.out.println("message::" + path );
			//  path是指欲下载的文件的路径。 
			response.setCharacterEncoding("UTF-8");
			File file  =   new  File(path);
			String filename  =  file.getName();
			int fileLength = (int)file.length();
			int                 length   = 0;
	        ServletOutputStream op       = response.getOutputStream();
	        ServletContext      context  = request.getSession().getServletContext();
	        String              mimetype = context.getMimeType( filename );
	        byte[]   byteContents   =   new   byte[fileLength];   
	        FileInputStream fis   =   new   FileInputStream(file);   
	        int   retcd   =   fis.read(byteContents);   
	        fis.close();    
	        logger.debug("mimetype:" + mimetype);
	        response.setContentType(mimetype == null?"application/vnd.ms-excel":mimetype );
	        response.setContentLength( retcd );
	        response.setHeader( "Content-Disposition", "attachment; filename=\"" + new String(filename.getBytes("gb2312"),"ISO-8859-1") + "\"" );
	        op.write(byteContents,0,retcd); 
	        op.close();
     }  catch  (IOException ex) {
         ex.printStackTrace();
     }
		return null;  
	} 
	 /**
	  * 书籍题录信息导出
	  * @param request
	  * @param response
	  * @return
	 * @throws Exception 
	  */
	@RequestMapping("/data/exportBookData.do")   
	public ModelAndView exportBookData(HttpServletRequest request,
			HttpServletResponse response) throws Exception { 
		try  {
			String ids = request.getParameter("ids");
			if(StringUtils.isEmpty(ids)){
				return null;
			}else{
				ids = ids.substring(0,ids.length()-1);
			}
			String path = this.exportBookData(ids);
			System.out.println("message::" + path );
			//  path是指欲下载的文件的路径。 
			response.setCharacterEncoding("UTF-8");
			File file  =   new  File(path);
			String filename  =  file.getName();
			int fileLength = (int)file.length();
			int                 length   = 0;
	        ServletOutputStream op       = response.getOutputStream();
	        ServletContext      context  = request.getSession().getServletContext();
	        String              mimetype = context.getMimeType( filename );
	        byte[]   byteContents   =   new   byte[fileLength];   
	        FileInputStream fis   =   new   FileInputStream(file);   
	        int   retcd   =   fis.read(byteContents);   
	        fis.close();    
	        logger.debug("mimetype:" + mimetype);
	        response.setContentType(mimetype == null?"application/vnd.ms-excel":mimetype );
	        response.setContentLength( retcd );
	        response.setHeader( "Content-Disposition", "attachment; filename=\"" + new String(filename.getBytes("gb2312"),"ISO-8859-1") + "\"" );
	        op.write(byteContents,0,retcd); 
	        op.close();
    }  catch  (IOException ex) {
        ex.printStackTrace();
    }
		return null;  
	} 
	/**
	 * 生成题录数据文件
	 * @return 生成的文件的路径
	 */
	public String exportData(String rids){
		String message = "false";
		 try {
				HSSFWorkbook wb = new HSSFWorkbook(); 
				 HSSFSheet sheet = wb.createSheet("new sheet"); 
				 HSSFRow row = sheet.createRow((short)0); 
				 row.createCell(0).setCellValue("分类号");
				 row.createCell(1).setCellValue("中文标题");
				 row.createCell(2).setCellValue("作者");
				 row.createCell(3).setCellValue("作者单位");
				 row.createCell(4).setCellValue("国家\\省市");
				 row.createCell(5).setCellValue("参文数");
				 row.createCell(6).setCellValue("刊名");
				 row.createCell(7).setCellValue("年份");
				 row.createCell(8).setCellValue("卷");
				 row.createCell(9).setCellValue("期");
				 row.createCell(10).setCellValue("页码");
				 row.createCell(11).setCellValue("ISSN编号");
				 row.createCell(12).setCellValue("国内代码");
				 row.createCell(13).setCellValue("内部代码");
				 row.createCell(14).setCellValue("出版地");
				 row.createCell(15).setCellValue("中文关键词");
				 row.createCell(16).setCellValue("中文主题词");
				 row.createCell(17).setCellValue("特征词");
				 row.createCell(18).setCellValue("更新日期");
				 row.createCell(19).setCellValue("英文标题");
				 row.createCell(20).setCellValue("中文摘要");
				 row.createCell(21).setCellValue("著者文摘");
				 row.createCell(22).setCellValue("文献类型");
				 row.createCell(23).setCellValue("基金");
				 row.createCell(24).setCellValue("语种");
				 row.createCell(25).setCellValue("人名主题");
				 row.createCell(26).setCellValue("CA");
				 CellStyle cs=wb.createCellStyle(); 
				 List  accList = DBMgr.getDbUtilInst().queryList("select * from CHD_PAPERINFO where id in("+rids+") order by id",null);
				 
				 
				 for(int i=0; i<accList.size(); i++){
						Map data = (Map)accList.get(i);
						HSSFRow onerow = sheet.createRow((short)(i+1)); 
						
						 onerow.createCell(0).setCellValue((String)data.get("CLASSNO")); 
						 onerow.createCell(1).setCellValue((String)data.get("TITLE")); 
						 onerow.createCell(2).setCellValue((String)data.get("AUTHOR")); 
						 onerow.createCell(3).setCellValue((String)data.get("AUTHORUNIT")); 
						 onerow.createCell(4).setCellValue((String)data.get("AREASTR")); 
						 onerow.createCell(5).setCellValue((String)data.get("CWNUM")); 
						 onerow.createCell(6).setCellValue((String)data.get("PERIODICALNAME")); 
						 onerow.createCell(7).setCellValue((String)data.get("YEARSTR")); 
						 onerow.createCell(8).setCellValue((String)data.get("VOLUME")); 
						 onerow.createCell(9).setCellValue((String)data.get("PERIOD")); 
						 onerow.createCell(10).setCellValue((String)data.get("PAGENO")); 
						 onerow.createCell(11).setCellValue((String)data.get("ISSNSTR")); 
						 onerow.createCell(12).setCellValue((String)data.get("CONTRYCODE")); 
						 onerow.createCell(13).setCellValue((String)data.get("CODESTR")); 
						 onerow.createCell(14).setCellValue((String)data.get("PUBLISHAREA")); 
						 onerow.createCell(15).setCellValue((String)data.get("KEYWORD")); 
						 onerow.createCell(16).setCellValue((String)data.get("SUBJECTWORD")); 
						 onerow.createCell(17).setCellValue((String)data.get("IMPRESSWORD")); 
						 onerow.createCell(18).setCellValue((String)data.get("UPDATEDATE")); 
						 onerow.createCell(19).setCellValue((String)data.get("TITLEN"));
						 onerow.createCell(20).setCellValue((String)data.get("ABSTRACT"));
						 onerow.createCell(21).setCellValue((String)data.get("AUTHORABSTRACT")); 
						 onerow.createCell(22).setCellValue((String)data.get("DOCUMENTTYPE")); 
						 onerow.createCell(23).setCellValue((String)data.get("FUNDNAME")); 
						 onerow.createCell(24).setCellValue((String)data.get("LANGUAGE")); 
						 onerow.createCell(25).setCellValue((String)data.get("USERSUBJECT")); 
						 onerow.createCell(26).setCellValue((String)data.get("CASTR"));
 				 }	
				 String tempFilepath = SystemUtil.getWebappRoot().toString();
				 tempFilepath = tempFilepath.replace("\\", "/") + "/temp";
				 System.out.println("tempFilepath::" + tempFilepath );
				 File tempfile = new File(tempFilepath);
				 if(!tempfile.exists()){
					 tempfile.mkdirs();
				 }
				 String destfile = tempFilepath + "/" + "冠心病期刊数据.xls";
				 FileOutputStream fileOut = new FileOutputStream(destfile); 
				 wb.write(fileOut); 
				 fileOut.close();
				 message = destfile;
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		return message;
		
	}
	/**
	 * 生成古书籍题录文件
	 * @return 生成的文件的路径
	 */
	public String exportBookData(String rids){
		String message = "false";
		 try {
				HSSFWorkbook wb = new HSSFWorkbook(); 
				 HSSFSheet sheet = wb.createSheet("new sheet"); 
				 HSSFRow row = sheet.createRow((short)0); 
				 row.createCell(0).setCellValue("条目编码");
				 row.createCell(1).setCellValue("书籍名称");
				 row.createCell(2).setCellValue("中医病名");
				 row.createCell(3).setCellValue("原文文本化");
				 row.createCell(4).setCellValue("卷册章节");
				 row.createCell(5).setCellValue("版本");
				 row.createCell(6).setCellValue("录入人");
				 row.createCell(7).setCellValue("录入日期");
				 row.createCell(8).setCellValue("朝代"); 
				 CellStyle cs=wb.createCellStyle(); 
				 List  accList = DBMgr.getDbUtilInst().queryList("select * from CHD_PAPERINFO where id in("+rids+") order by id",null);
				 
				 
				 for(int i=0; i<accList.size(); i++){
						Map data = (Map)accList.get(i);
						HSSFRow onerow = sheet.createRow((short)(i+1)); 
						
						 onerow.createCell(0).setCellValue(String.valueOf(data.get("ID"))); 
						 onerow.createCell(1).setCellValue((String)data.get("BOOKNAME")); 
						 onerow.createCell(2).setCellValue((String)data.get("TCMNAME")); 
						 onerow.createCell(3).setCellValue((String)data.get("ORIGINALTEXT")); 
						 onerow.createCell(4).setCellValue((String)data.get("VOLUMESECTION")); 
						 onerow.createCell(5).setCellValue((String)data.get("BOOKVERSION")); 
						 onerow.createCell(6).setCellValue((String)data.get("INPUTUSER")); 
						 onerow.createCell(7).setCellValue((String)data.get("INPUTDATE")); 
						 onerow.createCell(8).setCellValue((String)data.get("BOOKCD"));  
 				 }	
				 String tempFilepath = SystemUtil.getWebappRoot().toString();
				 tempFilepath = tempFilepath.replace("\\", "/") + "/temp";
				 System.out.println("tempFilepath::" + tempFilepath );
				 File tempfile = new File(tempFilepath);
				 if(!tempfile.exists()){
					 tempfile.mkdirs();
				 }
				 String destfile = tempFilepath + "/" + "冠心病古籍数据.xls";
				 FileOutputStream fileOut = new FileOutputStream(destfile); 
				 wb.write(fileOut); 
				 fileOut.close();
				 message = destfile;
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		return message;
		
	}
	
	 /**
	  *  数据导出
	  * @param request
	  * @param response
	  * @return
	 * @throws Exception 
	  */
	@RequestMapping("/data/exportAllData.do")   
	public ModelAndView exportAllData(HttpServletRequest request,
			HttpServletResponse response) throws Exception { 
		try  {
			String ids = request.getParameter("ids");
			if(StringUtils.isEmpty(ids)){
				return null;
			}else{
				ids = ids.substring(0,ids.length()-1);
			}
			String path = this.exportTxtData(ids);
			System.out.println("message::" + path );
			//  path是指欲下载的文件的路径。 
			response.setCharacterEncoding("UTF-8");
			File file  =   new  File(path);
			String filename  =  file.getName();
			int fileLength = (int)file.length();
			int                 length   = 0;
	        ServletOutputStream op       = response.getOutputStream();
	        ServletContext      context  = request.getSession().getServletContext();
	        String              mimetype = context.getMimeType( filename );
	        byte[]   byteContents   =   new   byte[fileLength];   
	        FileInputStream fis   =   new   FileInputStream(file);   
	        int   retcd   =   fis.read(byteContents);   
	        fis.close();    
	        logger.debug("mimetype:" + mimetype);
	        response.setContentType(mimetype == null?"text/plain":mimetype );
	        response.setContentLength( retcd );
	        response.setHeader( "Content-Disposition", "attachment; filename=\"" + new String(filename.getBytes("gb2312"),"ISO-8859-1") + "\"" );
	        op.write(byteContents,0,retcd); 
	        op.close();
    }  catch  (IOException ex) {
        ex.printStackTrace();
    }
		return null;  
	} 
	/**
	 * 生成题录数据文件
	 * @return 生成的文件的路径
	 */
	public String exportAllData(String rids){
		String message = "false";
		 try {
				HSSFWorkbook wb = new HSSFWorkbook(); 
				 HSSFSheet sheet = wb.createSheet("new sheet"); 
				 HSSFRow row = sheet.createRow((short)0); 
				 row.createCell(0).setCellValue("分类号");
				 row.createCell(1).setCellValue("中文标题");
				 row.createCell(2).setCellValue("作者");
				 row.createCell(3).setCellValue("作者单位");
				 row.createCell(4).setCellValue("国家\\省市");
				 row.createCell(5).setCellValue("参文数");
				 row.createCell(6).setCellValue("刊名");
				 row.createCell(7).setCellValue("年份");
				 row.createCell(8).setCellValue("卷");
				 row.createCell(9).setCellValue("期");
				 row.createCell(10).setCellValue("页码");
				 row.createCell(11).setCellValue("ISSN编号");
				 row.createCell(12).setCellValue("国内代码");
				 row.createCell(13).setCellValue("内部代码");
				 row.createCell(14).setCellValue("出版地");
				 row.createCell(15).setCellValue("中文关键词");
				 row.createCell(16).setCellValue("中文主题词");
				 row.createCell(17).setCellValue("特征词");
				 row.createCell(18).setCellValue("更新日期");
				 row.createCell(19).setCellValue("英文标题");
				 row.createCell(20).setCellValue("中文摘要");
				 row.createCell(21).setCellValue("著者文摘");
				 row.createCell(22).setCellValue("文献类型");
				 row.createCell(23).setCellValue("基金");
				 row.createCell(24).setCellValue("语种");
				 row.createCell(25).setCellValue("人名主题");
				 row.createCell(26).setCellValue("CA");
				 row.createCell(27).setCellValue("条目编码");
				 row.createCell(28).setCellValue("书籍名称");
				 row.createCell(29).setCellValue("中医病名");
				 row.createCell(30).setCellValue("原文文本化");
				 row.createCell(31).setCellValue("卷册章节");
				 row.createCell(32).setCellValue("版本");
				 row.createCell(33).setCellValue("录入人");
				 row.createCell(34).setCellValue("录入日期");
				 row.createCell(35).setCellValue("朝代"); 
				 CellStyle cs=wb.createCellStyle(); 
				 List  accList = DBMgr.getDbUtilInst().queryList("select * from CHD_PAPERINFO where id in("+rids+") order by id",null);
				 
				 
				 for(int i=0; i<accList.size(); i++){
						Map data = (Map)accList.get(i);
						HSSFRow onerow = sheet.createRow((short)(i+1)); 
						
						 onerow.createCell(0).setCellValue((String)data.get("CLASSNO")); 
						 onerow.createCell(1).setCellValue((String)data.get("TITLE")); 
						 onerow.createCell(2).setCellValue((String)data.get("AUTHOR")); 
						 onerow.createCell(3).setCellValue((String)data.get("AUTHORUNIT")); 
						 onerow.createCell(4).setCellValue((String)data.get("AREASTR")); 
						 onerow.createCell(5).setCellValue((String)data.get("CWNUM")); 
						 onerow.createCell(6).setCellValue((String)data.get("PERIODICALNAME")); 
						 onerow.createCell(7).setCellValue((String)data.get("YEARSTR")); 
						 onerow.createCell(8).setCellValue((String)data.get("VOLUME")); 
						 onerow.createCell(9).setCellValue((String)data.get("PERIOD")); 
						 onerow.createCell(10).setCellValue((String)data.get("PAGENO")); 
						 onerow.createCell(11).setCellValue((String)data.get("ISSNSTR")); 
						 onerow.createCell(12).setCellValue((String)data.get("CONTRYCODE")); 
						 onerow.createCell(13).setCellValue((String)data.get("CODESTR")); 
						 onerow.createCell(14).setCellValue((String)data.get("PUBLISHAREA")); 
						 onerow.createCell(15).setCellValue((String)data.get("KEYWORD")); 
						 onerow.createCell(16).setCellValue((String)data.get("SUBJECTWORD")); 
						 onerow.createCell(17).setCellValue((String)data.get("IMPRESSWORD")); 
						 onerow.createCell(18).setCellValue((String)data.get("UPDATEDATE")); 
						 onerow.createCell(19).setCellValue((String)data.get("TITLEN"));
						 onerow.createCell(20).setCellValue((String)data.get("ABSTRACT"));
						 onerow.createCell(21).setCellValue((String)data.get("AUTHORABSTRACT")); 
						 onerow.createCell(22).setCellValue((String)data.get("DOCUMENTTYPE")); 
						 onerow.createCell(23).setCellValue((String)data.get("FUNDNAME")); 
						 onerow.createCell(24).setCellValue((String)data.get("LANGUAGE")); 
						 onerow.createCell(25).setCellValue((String)data.get("USERSUBJECT")); 
						 onerow.createCell(26).setCellValue((String)data.get("CASTR"));
						 onerow.createCell(27).setCellValue(String.valueOf(data.get("ID"))); 
						 onerow.createCell(28).setCellValue((String)data.get("BOOKNAME")); 
						 onerow.createCell(29).setCellValue((String)data.get("TCMNAME")); 
						 onerow.createCell(30).setCellValue((String)data.get("ORIGINALTEXT")); 
						 onerow.createCell(31).setCellValue((String)data.get("VOLUMESECTION")); 
						 onerow.createCell(32).setCellValue((String)data.get("BOOKVERSION")); 
						 onerow.createCell(33).setCellValue((String)data.get("INPUTUSER")); 
						 onerow.createCell(34).setCellValue((String)data.get("INPUTDATE")); 
						 onerow.createCell(35).setCellValue((String)data.get("BOOKCD"));  
 				 }	
				 String tempFilepath = SystemUtil.getWebappRoot().toString();
				 tempFilepath = tempFilepath.replace("\\", "/") + "/temp";
				 System.out.println("tempFilepath::" + tempFilepath );
				 File tempfile = new File(tempFilepath);
				 if(!tempfile.exists()){
					 tempfile.mkdirs();
				 }
				 String destfile = tempFilepath + "/" + "冠心病导出数据.xls";
				 FileOutputStream fileOut = new FileOutputStream(destfile); 
				 wb.write(fileOut); 
				 fileOut.close();
				 message = destfile;
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		return message;
		
	}
	/**
	 * 生成题录数据文件（TXT）
	 * @return 生成的文件的路径
	 */
	public String exportTxtData(String rids){
		String message = "false";
		 try {
			 String tempFilepath = SystemUtil.getWebappRoot().toString();
			 tempFilepath = tempFilepath.replace("\\", "/") + "/temp";
			 System.out.println("tempFilepath::" + tempFilepath );
			 File tempfile = new File(tempFilepath);
			 if(!tempfile.exists()){
				 tempfile.mkdirs();
			 }
			 String destfile = tempFilepath + "/" + "export"+System.currentTimeMillis()+".txt";
			 FileOutputStream outSTr = null;      
			 BufferedOutputStream Buff = null;    
			      
			 String tab = "  ";      
			 String enter = "\r\n";      
			 List  accList = DBMgr.getDbUtilInst().queryList("select * from CHD_PAPERINFO where id in("+rids+") order by id",null);

			   StringBuffer write ;      
			    try {      
			        outSTr = new FileOutputStream(new File(destfile));      
			        Buff = new BufferedOutputStream(outSTr);      
			        for(int i=0; i<accList.size(); i++){
						Map data = (Map)accList.get(i);      
			            write = new StringBuffer(); 
			            String temp1 = null2str((String)data.get("CLASSNO"));
			            if(!"".equals(temp1))
			            	write.append("分类号:"+temp1+enter); 
			            String temp2 = null2str((String)data.get("TITLE"));
			            if(!"".equals(temp2))
			            	write.append("标题:"+temp2+enter); 
			            String temp3 = null2str((String)data.get("AUTHOR"));
			            if(!"".equals(temp3))
						write.append("作者:"+temp3+enter);
			            String temp4 = null2str((String)data.get("AUTHORUNIT"));
			            if(!"".equals(temp4))
			            	write.append("作者单位:"+temp4+enter);
			            String temp5 = null2str((String)data.get("AREASTR"));
			            if(!"".equals(temp5))
						write.append("国家\\省市:"+temp5+enter);
			            String temp6 = null2str((String)data.get("CWNUM"));
			            if(!"".equals(temp6))
			            	write.append("参文数:"+temp6+enter);
			            String temp7 = null2str((String)data.get("PERIODICALNAME"));
			            if(!"".equals(temp7))
						    write.append("刊名:"+temp7+enter);
			            String temp8 = null2str((String)data.get("YEARSTR"));
			            if(!"".equals(temp8))
			            	write.append("年份:"+temp8+enter);
			            String temp9 = null2str((String)data.get("VOLUME"));
			            if(!"".equals(temp1))
						write.append("卷:"+temp9+enter);
			            String temp10 = null2str((String)data.get("PERIOD"));
			            if(!"".equals(temp10))
						write.append("期:"+temp10+enter); 
			            String temp11 = null2str((String)data.get("PAGENO"));
			            if(!"".equals(temp11))
			            	write.append("页码:"+temp11+enter);
			            String temp12 = null2str((String)data.get("ISSNSTR"));
			            if(!"".equals(temp12))
			            	write.append("ISSN:"+temp12+enter); 
			            String temp13 = null2str((String)data.get("CONTRYCODE"));
			            if(!"".equals(temp13)) 
			            	write.append("国别:"+temp13+enter);
			            String temp14 = null2str((String)data.get("CODESTR"));
			            if(!"".equals(temp14))  
			            	write.append("地区:"+temp14+enter);
			            String temp15 = null2str((String)data.get("PUBLISHAREA"));
			            if(!"".equals(temp15)) 
						write.append("出版地:"+temp15+enter);
			            String temp16 = null2str((String)data.get("KEYWORD"));
			            if(!"".equals(temp16)) 
						write.append("关键词:"+temp16+enter);
			            String temp17 = null2str((String)data.get("SUBJECTWORD"));
			            if(!"".equals(temp17)) 
						write.append("主题词:"+temp17+enter);
			            String temp18 = null2str((String)data.get("IMPRESSWORD"));
			            if(!"".equals(temp18)) 
						write.append("特征词:"+temp18+enter);
			            String temp19 = null2str((String)data.get("UPDATEDATE"));
			            if(!"".equals(temp19)) 
						write.append("更新日期:"+temp19+enter);
			            String temp20 = null2str((String)data.get("TITLEN"));
			            if(!"".equals(temp20)) 
			            	write.append("英文标题:"+temp20+enter);
			            String temp21 = null2str((String)data.get("ABSTRACT"));
			            if(!"".equals(temp21)) 
						write.append("摘要:"+temp21+enter);
			            String temp22 = null2str((String)data.get("AUTHORABSTRACT"));
			            if(!"".equals(temp22)) 
						write.append("著者文摘:"+temp22+enter);
			            String temp23 = null2str((String)data.get("DOCUMENTTYPE"));
			            if(!"".equals(temp23)) 
						write.append("文献类型:"+temp23+enter);
			            String temp24 = null2str((String)data.get("FUNDNAME"));
			            if(!"".equals(temp24)) 
						write.append("基金:"+temp24+enter);
			            String temp25 = null2str((String)data.get("LANGUAGE"));
			            if(!"".equals(temp25)) 
						write.append("语种:"+temp25+enter);
			            String temp26 = null2str((String)data.get("USERSUBJECT"));
			            if(!"".equals(temp26)) 
						write.append("人名主题:"+temp26+enter);
			            String temp27 = null2str((String)data.get("CASTR"));
			            if(!"".equals(temp27)) 
						write.append("CA:"+temp27+enter);
			            String temp28 = null2str((String)data.get("BOOKNAME"));
			            if(!"".equals(temp28)) 
						write.append("书籍名称:"+temp28+enter); 
			            String temp29 = null2str((String)data.get("TCMNAME"));
			            if(!"".equals(temp29)) 
						write.append("中医病名:"+temp29+enter);
			            String temp30 = null2str((String)data.get("ORIGINALTEXT"));
			            if(!"".equals(temp30)) 
						write.append("原文文本化:"+temp30+enter);
			            String temp31 = null2str((String)data.get("VOLUMESECTION"));
			            if(!"".equals(temp31)) 
						write.append("卷册章节:"+temp31+enter);
			            String temp32 = null2str((String)data.get("BOOKVERSION"));
			            if(!"".equals(temp32)) 
						write.append("书籍版本:"+temp32+enter);
			            String temp33 = null2str((String)data.get("INPUTUSER"));
			            if(!"".equals(temp33)) 
						write.append("录入人:"+temp33+enter);
			            String temp34 = null2str((String)data.get("INPUTDATE"));
			            if(!"".equals(temp34)) 
					    write.append("录入日期:"+temp34+enter); 
			            String temp35 = null2str((String)data.get("BOOKCD"));
			            if(!"".equals(temp35)) 
					    write.append("朝代:"+temp35+enter);      
			            write.append(enter);          
			            Buff.write(write.toString().getBytes("UTF-8")); 
			            
			        }             
			        Buff.flush();      
			        Buff.close();      
			  } catch (Exception e) {      
			        e.printStackTrace();      
			    } finally {      
			        try {      
			           Buff.close();      
			            outSTr.close();      
			        } catch (Exception e) {      
			           e.printStackTrace();      
			        }      
			    }       
				 message = destfile;
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		return message;
		
	}
	private String null2str(String content){
		if(null == content || "null".equalsIgnoreCase(content)){
			return "";
		}
		return content;
	}
	/**
	 * 生成标准数据导出文件
	 * @return 生成的文件的路径
	 */
	public String exportStdData(String rid){
		String message = "false";
		 try {
				HSSFWorkbook wb = new HSSFWorkbook(); 
				 HSSFSheet sheet = wb.createSheet("stddata"); 
				 HSSFRow row = sheet.createRow((short)0); 
				 row.createCell(0).setCellValue("序号"); 
				 row.createCell(1).setCellValue("病名"); 
				 row.createCell(2).setCellValue("异名"); 
				 CellStyle cs=wb.createCellStyle(); 
				 List accList = null;
				 if("".equals(rid)){
					 accList = DBMgr.getDbUtilInst().queryList("select * from CHD_STANDWORD order by id",null);
				 }else{
					 accList = DBMgr.getDbUtilInst().queryList("select * from CHD_STANDWORD where id=? order by id",new Object[]{rid});
				 }
				 
				 for(int i=0; i<accList.size(); i++){
						Map data = (Map)accList.get(i);
						HSSFRow onerow = sheet.createRow((short)(i+1)); 
						Object obj  = data.get("id");
						if(obj instanceof Long){
							System.out.println("*****************");
						}else if(obj instanceof Integer){
							System.out.println("&&&&&&&&&&&&&");
						}else if(obj instanceof Double){
							System.out.println("################");
						}
						onerow.createCell(0).setCellValue(String.valueOf(data.get("id"))); 
						onerow.createCell(1).setCellValue((String)data.get("RIGHTNAME")); 
						onerow.createCell(2).setCellValue((String)data.get("OTHERNAME")); 
						 
				 }	
				 String tempFilepath = SystemUtil.getWebappRoot().toString();
				 tempFilepath = tempFilepath.replace("\\", "/") + "/temp";
				 System.out.println("tempFilepath::" + tempFilepath );
				 File tempfile = new File(tempFilepath);
				 if(!tempfile.exists()){
					 tempfile.mkdirs();
				 }
				 String destfile = tempFilepath + "/" + "病名标准数据.xls";
				 FileOutputStream fileOut = new FileOutputStream(destfile); 
				 wb.write(fileOut); 
				 fileOut.close();
				 message = destfile;
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		return message;
		
	}
	
	 /***
	  * 生成左侧分类树
	  * @param dbo
	  * @return
	  */
	 private Map getTreeStr(DBMgr dbo,String type){
		 Map hashMap = new HashMap();
		 StringBuffer tree1 = new StringBuffer("[");
		 StringBuffer tree2 = new StringBuffer("[");
		 StringBuffer tree3 = new StringBuffer("[");
		 StringBuffer tree4 = new StringBuffer("[");
		 String sql = "select * from CHD_TAGS where isdelete =1 and tagtype=" + type +
		 		" order by isroot";
		 List nodelist = dbo.queryList(sql, null);
		 for(int i =0;i<nodelist.size();i++){
			 Map data = (Map)nodelist.get(i);
			 String id = data.get("ID") + "";
			 String pid = data.get("PID") + "";
			 String code = (String)data.get("TAGCODE");
			 String name = (String)data.get("TAGNAME");
			 String ttype  =  data.get("TAGTYPE")+"";
			 //方剂分类
			 if("1".equals(ttype)){
				 tree1.append("{id:").append(id).append(",pId:").append(pid).append(",");
				 tree1.append("name:\"").append(name).append("\",open:true},");
			 //中药分类
			 }else if("2".equals(ttype)){
				 tree2.append("{id:").append(id).append(",pId:").append(pid).append(",");
				 tree2.append("name:\"").append(name).append("\",open:true},");
			 //证候分类
			 }else if("3".equals(ttype)){
				 tree3.append("{id:").append(id).append(",pId:").append(pid).append(",");
				 tree3.append("name:\"").append(name).append("\",open:true},");
			 //病名分类			
			 }else if("4".equals(ttype)){
				 tree4.append("{id:").append(id).append(",pId:").append(pid).append(",");
				 tree4.append("name:\"").append(name).append("\",open:true},");
			 } 
		 }
		 hashMap.put("treeStr1",cutStr(tree1.toString())+"]" );
		 hashMap.put("treeStr2",cutStr(tree2.toString())+"]" );
		 hashMap.put("treeStr3",cutStr(tree3.toString())+"]" );
		 hashMap.put("treeStr4",cutStr(tree4.toString())+"]");
		 return hashMap;
	 }
	 private static String cutStr(String str){
		 if(str.lastIndexOf(',') != -1){
			 str = str.substring(0, str.length()-1);
		 }
		 return str;
	 }
}
